package com.jinsi.controller.tang;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jinsi.constant.YltConstant;
import com.jinsi.pojo.Journal;
import com.jinsi.service.tang.OperationLogSService;
import com.jinsi.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 操作日志列表
 * @author 唐文博
 * @Date 2022-08-24
 */
@RestController
@RequestMapping("/logManagement")
@Slf4j
public class OperationLogSController {
    @Autowired
    private OperationLogSService operationLogService;

    /**
     * 查看表，全查，分页
     * @param page
     * @param limit
     * @param journalName
     * @param journalOperationList
     * @param journalOperation
     * @param timeTable
     * @return
     */
    @RequestMapping("/getOperationLog")
    public R getOperationLog(Integer page, Integer limit, String journalName,
                                               String journalOperationList, String journalOperation,
                                               String timeTable) {
        PageHelper.startPage(page, limit);
        List<Journal> list = operationLogService.getOperationLog(journalName,journalOperationList,
                journalOperation,timeTable);
        PageInfo<Journal> pageInfo = new PageInfo<>(list);
        return R.custom(YltConstant.LAYUI_CODE,
                YltConstant.LAYUI_MSG,
                pageInfo.getList(),
                pageInfo.getTotal());
    }

    /**
     * 删除接口
     * @param journalId
     * @return
     */
    @RequestMapping("/deleteOperationLog")
    public R deleteOperationLog(Integer journalId) {
        try {
            log.info("删除操作日志列表: [开始], 操作日志列表id:{}",journalId);
            operationLogService.deleteOperationLog(journalId);
            log.info("删除操作日志列表: [结束] 结果：{}","成功");
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            log.error("删除商品日志: [失败]", e);
            return R.error();
        }
    }
}
